<template>
    <div class="goods-list">
        <div class="goods-item" v-for="item in goodslist" :key="item.id" @click="goDetail(item.id)">
            <img :src="item.img_url" alt="" >
        <h3 class="phone-title">{{item.title}}</h3>
        <div class="info">
            <p class="price">
                <span class="now">￥{{ item.sell_price }}</span>
                <span class="old">￥{{ item.market_price }}</span>
            </p>
            <p class="sell">
                <span>
                    热卖中
                </span>
                <span>
                    剩{{ item.stock_quantity }}件
                </span>
            </p>
            </div>
        </div>
        <mt-button type="danger" size="large" @click="getMore()">加载更多</mt-button>

        </div>
</template>

<script>
import {Toast} from 'mint-ui'
export default {
    data(){
       return{
            pageindex:1,
            goodslist:[],
       }
    },
    created(){
        this.getGoodsList();
    },
    methods:{
        getGoodsList(){
            this.$http.get('http://www.liulongbin.top:3005/api/getgoods?pageindex='+this.pageindex).then(result=>{
                if(result.body.status === 0){
                    // this.goodslist = result.body.message;
                    this.goodslist = this.goodslist.concat(result.body.message);
                    // Toast("获取数据成功");
                }
            })
        },
        getMore(){
            this.pageindex++;
            this.getGoodsList();
        },
        goDetail(id){
            // 这是最简单的不根据ID。
            //  this.$router.push("/home/goodsinfo/"+id)
            //当根据ID跳转页面的时候
            this.$router.push({name:'goodsinfo',params:{id}})
            console.log(this)
        },
    }
}
</script>

<style  scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 7px;
    justify-content: space-between;
}
.goods-list .goods-item{
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 3px 0 ;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    
}
.goods-list .goods-item img{
    width:100%;
}
.goods-list .goods-item .phone-title{
    font-size: 15px;
    color: red;
}
.goods-list .goods-item .info .now {
    color: red;
    font-weight: bold;
    font-size: 16px;
}  
.goods-list .goods-item .info .old{
    text-decoration: line-through;
    margin-left: 7px;
}  
.goods-list .goods-item .info{
    background-color: #eee;
   
}
.goods-list .goods-item .info p{
    margin:0;
    padding: 5px;
}
.goods-list .goods-item .info .sell{
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}
    

</style>
